﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ds.DataBase.Model;

namespace Ds.DataBase.Migrations.SeedData
{
  public  class KeShiCreator
    {
        public static List<KeShi> KeShis { set; get; }
        private readonly UserInfoClassContext _context;

        static KeShiCreator()
        {
            //KeShis=new List<KeShi>
            //{
            //    new KeShi(){ZhiWeis =new List<ZhiWei>(),ksmc = "财务科"},
            //    new KeShi(){ZhiWeis =new List<ZhiWei>(),ksmc = "教务室"},
            //    new KeShi(){ZhiWeis =new List<ZhiWei>(),ksmc = "督考办"},
            //    new KeShi(){ZhiWeis =new List<ZhiWei>(),ksmc = "校长室"},
            //    new KeShi(){ZhiWeis =new List<ZhiWei>(),ksmc = "教学办公室"},
            //    new KeShi(){ZhiWeis =new List<ZhiWei>(),ksmc = "信息科"},
            //    new KeShi(){ZhiWeis =new List<ZhiWei>(),ksmc = "后勤科"}
            //};
        }
        public KeShiCreator(UserInfoClassContext context)
        {
            _context = context;
        }

        public void Create()
        {
            CreatePowerTrees();
        }

        private void CreatePowerTrees()
        {
            foreach (var language in KeShis)
            {
                AddLanguageIfNotExists(language);
            }
        }

        private void AddLanguageIfNotExists(KeShi keShi)
        {
            if (_context.KeShiContext.Any(l => l.ksmc == keShi.ksmc))
            {
                return;
            }
            _context.KeShiContext.Add(keShi);
            _context.SaveChanges();
        }
    }
}
